package com.sishu.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sishu.pojo.Asset;
import com.sishu.pojo.dto.Assetsdto;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


public interface AssetMapper extends BaseMapper<Asset> {

    @Select("SELECT * FROM asset WHERE s_id = #{sId} and group_id =#{groupId}")
    Asset selectbysId(String sId, String groupId);

    //总资产 ++ money  ,流动资产 ++ money
    @Update("UPDATE asset SET total_asset = total_asset + #{money} , fluid_asset = fluid_asset + #{money} WHERE s_id = #{sId} and group_id =#{groupId}")
    void updateasset(String sId, int money, String groupId);

    //总资产 不变 money  ,流动资产 ++ money
    @Update("UPDATE asset SET  fluid_asset = fluid_asset - #{money} ,fixed_asset =  fixed_asset  + #{money} WHERE s_id = #{sId} and group_id =#{groupId}")
    void buyground(String sId, int money, String groupId);

    @Update("UPDATE asset SET  fluid_asset = fluid_asset - #{money} ,fixed_asset =  fixed_asset  + #{price} ,total_asset = fluid_asset + fixed_asset WHERE s_id = #{sId} and group_id =#{groupId}")
    void buyground2(String sId, int money, int price, String groupId);//money是优惠后的价格   price是地块本来的价格 针对销售

    @Update("UPDATE asset SET  fluid_asset = fluid_asset + #{money} ,fixed_asset =  fixed_asset  - #{price},total_asset = fluid_asset + fixed_asset WHERE s_id = #{sId} and group_id =#{groupId}")
    void saleground(String sId, int money, int price, String groupId); //money是0.8倍卖地的价格   price是地块本来的价格


    //根据groupid查询资产表所有信息,加上student表的用户名
    @Select("SELECT asset.id,asset.s_id,asset.group_id,asset.fixed_asset,asset.fluid_asset,asset.total_asset,student.s_name,role.level_name " +
            "FROM asset JOIN student on asset.s_id = student.s_id " +
            "JOIN gus ON asset.s_id = gus.s_id AND asset.group_id = gus.group_id " +
            "JOIN role ON role.role_id = gus.role_id " +
            "where asset.group_id =#{groupId}" +
            " order by s_id")
    List<Assetsdto> selectbygroupid(String groupId);

    //根据groupid查询资产表所有信息,加上student表的用户名
    @Select("SELECT asset.id,asset.s_id,asset.group_id,asset.fixed_asset,asset.fluid_asset,asset.total_asset,student.s_name " +
            "FROM asset JOIN student on asset.s_id = student.s_id " +
            "JOIN gus ON asset.s_id = gus.s_id AND asset.group_id = gus.group_id  " +
            "where asset.group_id =#{groupId}")
    List<Assetsdto> selectbygroupid2(String groupId);

    @Update("UPDATE asset SET fluid_asset = #{money},total_asset = fixed_asset + fluid_asset WHERE s_id = #{sId} and group_id =#{groupId}")
    void reviveasset(String sId, String groupId, int money);

}
